package com.coder.oj.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.coder.oj.common.core.JsonPage;
import com.coder.oj.common.core.R;
import com.coder.oj.common.entity.Problem;
import com.coder.oj.common.mapper.ProblemMapper;
import com.coder.oj.system.mapstruct.ProblemMapstruct;
import com.coder.oj.system.query.ProblemQuery;
import com.coder.oj.system.service.ProblemService;
import com.coder.oj.system.vo.ProblemVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@Api(tags = {"题目管理"})
@RestController
@RequestMapping("/problem")
public class ProblemController {

    @Autowired
    private ProblemService problemService;

    @Autowired
    private ProblemMapper problemMapper;

    @Autowired
    private ProblemMapstruct problemMapstruct;

    @PostMapping("/page")
    @ApiOperation("分页查询")
    public R<JsonPage<ProblemVo>> getProblemPage(@RequestBody ProblemQuery params) {
        return R.ok().setResult(problemService.getProblemPage(params));
    }

    @GetMapping
    @ApiOperation("题目详情")
    public R<ProblemVo> getProblemById(@RequestParam("id") Long id) {
        return R.ok().setResult(problemMapstruct.toVO(problemMapper.selectById(id)));
    }

    @GetMapping("/random")
    @ApiOperation("题目推荐")
    public R<List<ProblemVo>> getRandomProblem(@RequestParam("limit") Integer limit) {
        return R.ok().setResult(problemService.getRandomProblem(limit));
    }

    @GetMapping("/tag")
    @ApiOperation("标签墙")
    public R<List<String>> getTagWall() {
        return R.ok().setResult(problemService.getTagWall());
    }
}
